package se.webbzon.boltzmann.editor.component.itemlist;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;

import javax.swing.JList;
import javax.swing.ListCellRenderer;

import se.webbzon.boltzmann.editor.list.EditorListCell;
import se.webbzon.boltzmann.item.AbstractItem;

public class ItemListCell extends EditorListCell implements ListCellRenderer<AbstractItem> {
	
	// Auto generated serial version UID
	private static final long serialVersionUID = -2407592227869757827L;
	
	// The world object associated with this list cell
	private AbstractItem item;
	
	/*============================================================
	Constructors
	============================================================*/
	
	public ItemListCell(Dimension d) {
		super(d);
	}
	
	/*============================================================
	Public Methods
	============================================================*/
	
	@Override public void paintComponent(Graphics g) {
		super.paintComponent(g);
		g.setFont(getFont());
		if (item != null) {
			g.drawImage(item.getTextureSet().get(0).getImage(), 0, 0, 64, 64, this);
			g.drawString(item.getName(), 80, 32);
		} else
			g.drawString("No Item (null)", 8, 32);
	}

	@Override
	public Component getListCellRendererComponent(
			JList<? extends AbstractItem> list, AbstractItem item, int index,
			boolean isSelected, boolean cellHasFocus) {
		setSelected(isSelected);
		this.item = item;
		return this;
	}

}
